import Vue from 'vue'
 import Vuex from 'vuex'
import Router from 'vue-router'
import header from '@/components/header'
import recommend from '@/components/pages/recommend'
import login from '@/components/login/login';
import space from '@/components/space/space';
Vue.use(Router)

const router= new Router({
  routes: [
//  {
//  	path:'/',
//  	name:'tuijian',
//  	component:tuijian
//  },{
//  	path:'/flash',
//  	component:flash
//  },{
//  	path:'/hotdog',
//  	component:hotdog
//  {
//  	path:'/add',
//  	component:add
//  },
	{
    	path:'/recommend',
    	name:'recommend',
    	component:recommend
   },
   {
    	path:'/login/',
    	name:'login',
    	component:login
   },
   {
   		path:'/space/',
    	name:'space',
    	component:space,
    	meta:{
    		requireAuth:true
    	}
   	}
  ]
})
export default router

//全局守卫
router.beforeEach((to,from,next)=>{
	if(to.matched.some(record=>record.meta.requireAuth)){
		if(localStorage.getItem("isLogin")){
			next()
		}else{
			next({
				path:'/login',
				query:{
					redirect:to.fullPath
				}
			})
		}
	}else{
		next()
	}
	console.log(to)
	console.log(from)
})
